package com.jian.service;

import com.jian.util.JDBCUtils;

import javax.servlet.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Jiange
 * @create 2021-04-11-22:30
 */
public class MyFilter implements Filter {
    private static ThreadLocal threadLocal = new ThreadLocal();
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Filter开始");
        try{
            filterChain.doFilter(servletRequest,servletResponse);
            System.out.println("错误");
            JDBCUtils.CloseConnectionSubmit();
            System.out.println("关闭了连接");
        }catch (Exception exception){
            System.out.println("回滚");
            try {
                JDBCUtils.CloseRollback();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("Filter结束");
    }
}
